package com.ourteam.product.requirement.api;

import com.ourteam.frame.web.AbstractTreeNodeBuilder;
import com.ourteam.product.requirement.domain.ProductCatalogBean;
import com.ourteam.product.requirement.service.IProductCatalogService;
import com.ourteam.product.requirement.service.ProductCatalogServiceFactory;

public class ProductCatalogSubNodeBuilder extends AbstractTreeNodeBuilder<ProductCatalogBean, ProductCatalogBean> {

	private static final IProductCatalogService PRODUCT_CATALOG_SERVICE = ProductCatalogServiceFactory
			.getProductCatalogService();

	@Override
	public ProductCatalogBean[] getTreeNodeObjects(ProductCatalogBean parentObject) throws Exception {

		long parentId = 0;

		if (parentObject != null) {
			parentId = parentObject.getId();
		}

		return PRODUCT_CATALOG_SERVICE.getProductCatalogs(parentId);
	}

	@Override
	public Object getNodeId(ProductCatalogBean childObject) throws Exception {
		return childObject.getId();
	}

	@Override
	public boolean isLeaf(ProductCatalogBean childObject) throws Exception {
		return false;
	}

	@Override
	public int getChildCount(ProductCatalogBean childObject) throws Exception {
		return 0;
	}

	@Override
	public String getNodeDefineId(ProductCatalogBean childObject) throws Exception {
		return "productCatalog";
	}

	@Override
	public ProductCatalogBean converToParentObject(Object parent) throws Exception {
		if (parent != null) {
			return PRODUCT_CATALOG_SERVICE.getProductCatalogById(Long.parseLong(parent.toString()));
		}
		return null;
	}

}
